﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

using System.Xml;
using System.IO;
using System.Xml.Serialization;
public partial class 序列化类型_XmlSerialize : System.Web.UI.Page
{
    TestSerialize MyTest = new TestSerialize();
    protected void Page_Load(object sender, EventArgs e)
    {

        Label1.Text = Server.HtmlEncode(MyTest.SerializeClassToXML()).Replace("\r\n", "<br/>").Replace("\t", " &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;");
    }






}

/// <summary>
/// 序列化类型
/// </summary>
public class TestSerialize
{   
        /// <summary>
            /// 序列化的对象
        /// </summary>
    Tong.TongTreeDataTable TextData = new Tong.TongTreeDataTable();

        /// <summary>
        /// 用于序列化的 write 
        /// </summary>
        StringWriter Write = new StringWriter();

        /// <summary>
        /// 开始定义用于序列化的新实例
        /// </summary>
        XmlSerializer MySerialize;


    /// <summary>
    /// 使用XML序列化
    /// </summary>
    public string SerializeClassToXML()
    {
        DataTable MYdt = TextData.TreeTable("TreeClass", "ID", "ID", "ClassName", "followid");
        MYdt.TableName = "dddd";
        MySerialize = new XmlSerializer(MYdt.GetType()); ;
        MySerialize.Serialize(Write, MYdt);
        
        return Write.ToString();
    }
}

public class test {
    string pp;
    public void oo() { }
    public string Pp
    {
        get { return pp; }
        set { pp = value; }
    }
}